//
//  VDead.m
//  Void Dead
//
//  Created by Sidney Just on 03.07.09.
//  Copyright 2009 by Sidney Just
//  This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; 
//  either version 3 of the License, or (at your option) any later version.
//  
//  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 
//  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//  


#import "VDead.h"

#pragma mark -
#pragma mark Umwandel funktionen


void vec_to_col(VD_Color *col, VD_Vector *vec)
{
	col.red = vec.x;
	col.green = vec.y;
	col.blue = vec.z;
}


void col_to_vec(VD_Vector *vec, VD_Color *col)
{
	vec.x = col.red;
	vec.y = col.green;
	vec.z = col.blue;
}


#pragma mark -
#pragma mark Helfer

VD_Vector* vector(GLfloat x, GLfloat y, GLfloat z)
{
	VD_Vector *temp = [[[VD_Vector alloc] init] autorelease];
	temp.x = x; 
	temp.y = y;
	temp.z = z;
	return temp;
}


VD_Color* color(GLfloat red, GLfloat green, GLfloat blue)
{
	VD_Color *temp = [[[VD_Color alloc] init] autorelease];
	temp.red = red; 
	temp.green = green;
	temp.blue = blue;
	return temp;
}

void ptr_remove(id ptr)
{
	[ptr release];
	ptr = NULL;
}

#pragma mark -
#pragma mark Vektor funktionen

void vec_set(VD_Vector *vector1, VD_Vector *vector2)
{
	vector1.x = vector2.x;
	vector1.y = vector2.y;
	vector1.z = vector2.z;
}

void vec_fill(VD_Vector *vec, float fill)
{
	vec.x = fill;
	vec.y = fill;
	vec.z = fill;
}

void vec_add(VD_Vector *vector1, VD_Vector *vector2)
{
	vector1.x += vector2.x;
	vector1.y += vector2.y;
	vector1.z += vector2.z;
}

void vec_sub(VD_Vector *vector1, VD_Vector *vector2)
{
	vector1.x -= vector2.x;
	vector1.y -= vector2.y;
	vector1.z -= vector2.z;
}

float vec_dist(VD_Vector *vector1, VD_Vector *vector2)
{
	VD_Vector *temp = [[VD_Vector alloc] init];
	
	temp.x = vector1.x - vector2.x;
	temp.y = vector1.y - vector2.y;
	temp.z = vector1.z - vector2.z;
	
	float distanz = sqrt((temp.x*temp.x) + (temp.y*temp.y) + (temp.z*temp.z));   
	[temp release];
	return distanz;
}

void vec_inverse(VD_Vector *vec)
{
	vec.x = -vec.x;
	vec.y = -vec.y;
	vec.z = -vec.z;
}

float vec_length(VD_Vector *vec)
{
	return vec_dist(vec, vector(0, 0, 0));
}

void vec_scale(VD_Vector *vec, float factor)
{
	vec.x *= factor;
	vec.y *= factor;
	vec.z *= factor;
}

#pragma mark -
#pragma mark Color funktionen

void col_set(VD_Color *col1, VD_Color *col2)
{
	col1.red = col2.red;
	col1.green = col2.green;
	col1.blue = col2.blue;
}